package spring_mybatis.test;

import java.sql.Date;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import www.albert.springMybatis.entry.User;
import www.albert.springMybatis.mapper.UserMapper;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext-mapper.xml"})
public class SMTest_mapper {
    
    @Autowired
    private UserMapper userMapper;
    
    @Test
    @Transactional
    public void findUserById() {
        User user = userMapper.findUserById(1);
        System.out.println(user);
    }
    
    @Test
    @Transactional
    public void insertUser() {
        User user = new User(); 
        user.setAge(12);
        user.setName("Tom");
        user.setBirthday(new Date(System.currentTimeMillis() - 19940312));
        
        int value = userMapper.insertUser(user);
        System.out.println(user);
    }
    
    @Test
    @Transactional
    public void deleteUser() {
        int value = userMapper.deleteUser(1);
        System.out.println(value);
    }

}
